using StockTraderRI.Infrastructure.Messaging;
using StockTraderRI.Modules.News.Contract;
using StockTraderRI.Modules.News.Model;

namespace StockTraderRI.Modules.News.Client
{
    public class NewsHandler : IHandler<NewsMessage>
    {
        private readonly INewsCache cache;

        public NewsHandler(INewsCache cache)
        {
            this.cache = cache;
        }

        public void Handle(NewsMessage message)
        {
            cache.AddNews(message.News.TickerSymbol, CreateArticle(message));
        }

        private NewsArticle CreateArticle(NewsMessage message)
        {
            return new NewsArticle
                       {
                           Title = message.News.Title,
                           Body = message.News.Body,
                           PublishedDate = message.DatePublished,
                           IconUri = "/StockTraderRI.Modules.News;Component/Data/Images/Annotation_New.png"
                       };
        }
    }
}